package lelouet.datacenter.thermal.impacts;

public class ThermalEvaluator {

	/**
	 * gives a note for each server, according to how it can thermaly impact
	 * other servers with given consumption.<br />
	 * the lower the note, the better the server
	 * 
	 * @param impacts
	 *            the thermal impacts of the servers
	 * 
	 * @param consumptions
	 *            the map of consumptions of the servers. If there are some
	 *            servers in this map that are not in the impacts, they are not
	 *            considered but an error is printed. If some servers have no
	 *            consumption, then it is assumed to be 0
	 * 
	 * @return an array of the associated note. the indexes are corresponding to
	 *         impacts.getServersIndexes
	 */
	public static double[] thermalVictimRanking(LinearModel impacts,
			double[] consumptions) {
		double[] maxIncreases = impacts.maxHeatIncrease(consumptions);
		double[] ret = new double[impacts.size()];
		for (int i = 0; i < ret.length; i++) {
			for (int j = 0; j < ret.length; j++) {
				ret[i] += maxIncreases[j] * impacts.getImpact(i, j);
			}
		}
		for (int impacterIndex = 0; impacterIndex < impacts.size(); impacterIndex++) {
			double consumption = consumptions[impacterIndex];
			ret[impacterIndex] *= consumption;
		}
		return ret;
	}

}
